package com.cby.android.olive.tool

import android.graphics.ColorMatrix
import android.graphics.Paint
import android.graphics.ColorMatrixColorFilter
import android.view.View


/**
 * @description: 设置APP的view灰白模式效果
 * @author: ChenBaoYang
 * @createDate: 2022/12/3 10:24 上午
 */
object GrayManager {

    private var mGrayPaint: Paint? = null

    init {
        initParam()
    }

    private fun initParam() {
        val mGrayMatrix = ColorMatrix()
        mGrayPaint = Paint()
        mGrayMatrix.setSaturation(0f)
        mGrayPaint!!.colorFilter = ColorMatrixColorFilter(mGrayMatrix)
    }


    /**
     * 硬件加速置灰方法
     */
    fun setLayerGrayType(view: View) {
        if (mGrayPaint == null) {
            initParam()
        }
        view.setLayerType(View.LAYER_TYPE_HARDWARE, mGrayPaint)
    }
}